package com.qf.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.qf.*;
import com.qf.mapper.*;
import com.qf.service.SeatService;
import com.qf.vo.MsgVO;
import org.apache.lucene.search.similarities.Lambda;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * 作者：Xx凯丶
 * 时间：2022/4/22 9:40
 */
@Service
public class SeatServiceImpl implements SeatService {
    @Autowired
    SeatMapper seatMapper;
    @Autowired
    private MovieMapper movieMapper;
    @Autowired
    private ScenesMapper scenesMapper;
    @Autowired
    private CinemaMapper cinemaMapper;
    @Autowired
    private HallMapper hallMapper;
    @Override
    public ResultVo searchSeatByCinemaIdAndHallId(Integer cinemaId, Integer hallId) {
        List<Seat> seats = seatMapper.selectSeatByCinemaIdAndHallId(cinemaId, hallId);
        Map<Integer,List<Seat>> seatMap=new HashMap<>();
        seats.forEach(seat -> {
            seatMap.put(seat.getRow(), new ArrayList<Seat>());
        });
        seats.forEach(seat -> {
            List<Seat> list = seatMap.get(seat.getRow());
            list.add(seat);
        });
        return new ResultVo(200,"SUCCESS",seatMap);
    }

    @Override
    public ResultVo searchRowByCinemaIdAndHallId(Integer cinemaId, Integer hallId) {
        List<Integer> rows = seatMapper.selectRowByCinemaIdAndHallId(cinemaId, hallId);
        return new ResultVo(200,"success",rows);
    }

    @Override
    public MsgVO searchMsgByCinemaIdAndMovieIdAndHallIdAndScenesId(Integer cinemaId, Integer movieId, Integer hallId, Integer scenesId) {
        LambdaQueryChainWrapper<Movie> wrapper1 = new LambdaQueryChainWrapper(movieMapper);
        Movie movie = wrapper1
                .eq(Movie::getMovieId, movieId)
                .one();
        List<String> types = movieMapper.selectTypeByMovieId(movieId);
        movie.setTypes(types);
        LambdaQueryChainWrapper<Scenes> wrapper2 = new LambdaQueryChainWrapper<>(scenesMapper);
        Scenes scenes = wrapper2.eq(Scenes::getScenesId, scenesId).one();
        LambdaQueryChainWrapper<Cinema> wrapper3 = new LambdaQueryChainWrapper<>(cinemaMapper);
        Cinema cinema = wrapper3.eq(Cinema::getCinemaId, cinemaId).one();
        LambdaQueryChainWrapper<Hall> wrapper4 = new LambdaQueryChainWrapper<>(hallMapper);
        Hall hall = wrapper4.eq(Hall::getHallId, hallId).one();
        MsgVO msgVO = new MsgVO(movie.getMovieCh(),movie.getImage(),movie.getTypes(),movie.getMovieTime(),cinema.getCinemaName(),hall.getHallName(),scenes.getLanguage(),scenes.getPlayTime(),scenes.getPrice());
        return msgVO;
    }
}
